//
//  TabBarViewController.m
//  SmartCup
//
//  Created by Kendama on 2017/5/16.
//  Copyright © 2017年 DT. All rights reserved.
//

#import "TabBarViewController.h"
#import "HYDeviceManagerVC.h"
#import "HYDeviceAddVC.h"
#import "HYWarningRecordVC.h"
#import "HYUserCenterVC.h"

@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTabBarItem];

//    [[UITabBar appearance] setShadowImage:[UIImage new]];
//    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
}


- (void)setTabBarItem
{
    
    HYDeviceManagerVC *homeVC = [[HYDeviceManagerVC alloc] init];
    homeVC.tabBarItem.title = @"设备管理";
    
    HYDeviceAddVC *pm25VC = [[HYDeviceAddVC alloc] init];
    pm25VC.tabBarItem.title = @"设备添加";
    
    HYWarningRecordVC *kidsVC = [[HYWarningRecordVC alloc] init];
    kidsVC.tabBarItem.title = @"报警记录";
    
    HYUserCenterVC *settingVC = [[HYUserCenterVC alloc] init];
    settingVC.tabBarItem.title = @"个人中心";
    
    self.viewControllers = @[[self giveMeNavWithVC:homeVC andImgName:@"tab_Administration_nor" andSelectedImgName:@"tab_Administration_pre"],
                             [self giveMeNavWithVC:pm25VC andImgName:@"tab_add_nor" andSelectedImgName:@"tab_add_pre"],
                             [self giveMeNavWithVC:kidsVC andImgName:@"tab_Record_nor" andSelectedImgName:@"tab_Record_pre"],
                             [self giveMeNavWithVC:settingVC andImgName:@"tab_Center_nor" andSelectedImgName:@"tab_Center_pre"]
                            ];

    
}

- (UIViewController *)giveMeVC:(UIViewController *)VC andImgName:(NSString *)imgName andSelectedImgName:(NSString *)selImgName
{
    //    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] tag:0];
    VC.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] selectedImage:[self removeRendering:selImgName]];
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}
                                  forState:UIControlStateNormal];
    [VC.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]} forState:UIControlStateHighlighted];
    //    [nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -12)];
    //    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor yellowColor]};
    return VC;
}


/**
 *  快速创建Nav
 */
- (UINavigationController *)giveMeNavWithVC:(UIViewController *)VC andImgName:(NSString *)imgName andSelectedImgName:(NSString *)selImgName
{
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:VC];
//    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] tag:0];
    nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:VC.tabBarItem.title image:[self removeRendering:imgName] selectedImage:[self removeRendering:selImgName]];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}
                                  forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateHighlighted];
//    [nav.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -12)];
//    nav.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor yellowColor]};
    return nav;
}


/**
 *  返回取消渲染的image
 */
- (UIImage *)removeRendering:(NSString *)imageName
{
    UIImage * image = [UIImage imageNamed:imageName];
    return [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}



@end
